//
//  FourViewController4_2.m
//  真·豆瓣半完全体
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "FourViewController4_2.h"
#import "AdminView.h"
#import "adminDataBaseHandle.h"
#import "adminModel.h"
@interface FourViewController4_2 ()<UITextFieldDelegate>

@property (nonatomic, retain) adminModel *model;
@property (nonatomic, retain) AdminView *adminView;
@property (nonatomic, retain) AdminView *adminView2;
@property (nonatomic, retain) AdminView *adminView3;
@property (nonatomic, retain) AdminView *adminView4;
@property (nonatomic, retain) AdminView *adminView5;

@end

@implementation FourViewController4_2
- (void)dealloc{
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"注册";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1];
    self.navigationController.navigationBar.translucent = NO;
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
    self.navigationItem.rightBarButtonItem = item;
    
    
    [self createAdminView];

}

- (void)itemAction:(UIBarButtonItem *)item{
    self.model =[adminModel adminModel];
    
    _model.name = _adminView.tf.text;
    
    _model.code = _adminView2.tf.text;
    
    _model.email = _adminView4.tf.text;
    
    _model.phone = _adminView5.tf.text;
    [[adminDataBaseHandle sharedAdminDataBaseHandle] insertModel:_model];
    [self.navigationController popToRootViewControllerAnimated:YES];
}









/** 创建控件 */
- (void) createAdminView{
    self.adminView = [[AdminView alloc] initWithFrame:CGRectMake(10, 40, 375, 50)];
    _adminView.Label.text = @"用户名:";
    _adminView.tf.placeholder = @"请输入用户";
    _adminView.tf.delegate = self;
    [self.view addSubview:_adminView];
    [_adminView release];
    
    self.adminView2 = [[AdminView alloc] initWithFrame:CGRectMake(10, 100, 375, 50)];
    _adminView2.Label.text = @"密码:";
    _adminView2.tf.placeholder = @"请输入密码";
    _adminView2.tf.enabled = YES;
    _adminView2.tf.delegate = self;
    [self.view addSubview:_adminView2];
    [_adminView2 release];
    
    self.adminView3 = [[AdminView alloc] initWithFrame:CGRectMake(10, 160, 375, 50)];
    _adminView3.Label.text = @"确认密码:";
    _adminView3.tf.placeholder = @"请再次输入密码";
    _adminView3.tf.enabled = YES;
    _adminView3.tf.delegate = self;
    [self.view addSubview:_adminView3];
    [_adminView3 release];
    
    self.adminView4 = [[AdminView alloc] initWithFrame:CGRectMake(10, 220, 375, 50)];
    _adminView4.Label.text = @"邮箱:";
    _adminView4.tf.placeholder = @"请输入邮箱";
    _adminView4.tf.delegate = self;
    [self.view addSubview:_adminView4];
    [_adminView4 release];
    
    self.adminView5 = [[AdminView alloc] initWithFrame:CGRectMake(10, 280, 375, 50)];
    _adminView5.Label.text = @"联系方式:";
    _adminView5.tf.placeholder = @"请输入联系方式";
    _adminView5.tf.delegate = self;
    _adminView5.tf.keyboardType = UIKeyboardTypeNumberPad;
    [self.view addSubview:_adminView5];
    [_adminView5 release];
    
    

}

#pragma mark - TextFiledDelegate
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{


    return YES;
}
- (void) textFieldDidEndEditing:(UITextField *)textField{
 
}

- (void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [_adminView.tf resignFirstResponder];
    [_adminView2.tf resignFirstResponder];
    [_adminView3.tf resignFirstResponder];
    [_adminView4.tf resignFirstResponder];
    [_adminView5.tf resignFirstResponder];
}
- (BOOL) textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
